<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns the BSON representation of a JSON value</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="ref.bson.functions.html">« 函数</a></li>
      <li style="float: right;"><a href="function.mongodb.bson-fromphp.html">MongoDB\BSON\fromPHP »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.bson.functions.html">函数</a></li>
    <li>Returns the BSON representation of a JSON value</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.mongodb.bson-fromjson" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoDB\BSON\fromJSON</h1>
  <p class="verinfo">(mongodb &gt;=1.0.0)</p><p class="refpurpose"><span class="refname">MongoDB\BSON\fromJSON</span> &mdash; <span class="dc-title">Returns the BSON representation of a JSON value</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.mongodb.bson-fromjson-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>MongoDB\BSON\fromJSON</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$json</code></span>): <span class="type">string</span></div>

  <p class="para rdfs-comment">
   Converts an
   <a href="https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/" class="link external">&raquo;&nbsp;extended JSON</a>
   string to its BSON representation.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mongodb.bson-fromjson-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">json</code> (<span class="type">string</span>)</dt>

    <dd>

     <p class="para">
      JSON value to be converted.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mongodb.bson-fromjson-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   The serialized BSON document as a binary string.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.mongodb.bson-fromjson-errors">
  <h3 class="title">错误／异常</h3>
  <ul class="simplelist">
   <li class="member">
    Throws
    <span class="classname"><a href="class.mongodb-driver-exception-unexpectedvalueexception.html" class="classname">MongoDB\Driver\Exception\UnexpectedValueException</a></span> if
    the JSON value cannot be converted to BSON (e.g. due to a syntax error).
   </li>
  </ul>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mongodb.bson-fromjson-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-1367">
   <p><strong>示例 #1 <span class="function"><strong>MongoDB\BSON\fromJSON()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$json&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'{&nbsp;"_id":&nbsp;{&nbsp;"$oid":&nbsp;"563143b280d2387c91807965"&nbsp;}&nbsp;}'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$bson&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">BSON</span><span style="color: #007700">\</span><span style="color: #0000BB">fromJSON</span><span style="color: #007700">(</span><span style="color: #0000BB">$json</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$value&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">BSON</span><span style="color: #007700">\</span><span style="color: #0000BB">toPHP</span><span style="color: #007700">(</span><span style="color: #0000BB">$bson</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$value</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程会输出：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
object(stdClass)#2 (1) {
  [&quot;_id&quot;]=&gt;
  object(MongoDB\BSON\ObjectId)#1 (1) {
    [&quot;oid&quot;]=&gt;
    string(24) &quot;563143b280d2387c91807965&quot;
  }
}
</pre></div>
   </div>
  </div>
 </div>



 <div class="refsect1 seealso" id="refsect1-function.mongodb.bson-fromjson-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="function"><a href="function.mongodb.bson-tojson.html" class="function" rel="rdfs-seeAlso">MongoDB\BSON\toJSON()</a> - Returns the Legacy Extended JSON representation of a BSON value</span></li>
   <li class="member"><a href="https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/" class="link external">&raquo;&nbsp;MongoDB Extended JSON</a></li>
   <li class="member"><a href="https://www.mongodb.com/docs/manual/reference/bson-types/" class="link external">&raquo;&nbsp;MongoDB BSON</a></li>
  </ul>
 </div>


</div></div></div></body></html>